package net.youyi.crazycopyer.adapters;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import net.youyi.crazycopyer.R;
import net.youyi.crazycopyer.entity.Copy;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xzp on 15/11/6.
 */
public class CopyAdapter extends BaseRecyclerAdapter<Copy>{
    public int[] drawables={R.drawable.bili_icon,-1,-1};
    public CopyAdapter(Context context) {
        super(context);
        String[] names=context.getResources().getStringArray(R.array.copy_list);
        List<Copy> copyList=new ArrayList<Copy>();
        for(int i=0;i<names.length;i++){
            Copy copy=new Copy();
            copy.setDrawable(drawables[i]);
            copy.setName(names[i]);
            copyList.add(copy);
        }
        setList(copyList);
    }

    @Override
    public RecyclerView.ViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(getContext()).inflate(R.layout.copy_item,parent,false);
        return new CopyHolder(view);
    }

    @Override
    public void onBindHolder(RecyclerView.ViewHolder holder, int position) {
        CopyHolder copyHolder= (CopyHolder) holder;
        Copy copy=getList().get(position);
        copyHolder.titleText.setText(copy.getName());
        if(copy.getDrawable()>0)
            copyHolder.image.setImageResource(copy.getDrawable());
        else
            copyHolder.image.setImageDrawable(null);
    }
    private class CopyHolder extends ClickableViewHolder{
        private ImageView image;
        private AppCompatTextView titleText;
        public CopyHolder(View itemView) {
            super(itemView);
            image= (ImageView) itemView.findViewById(R.id.copy_image);
            titleText= (AppCompatTextView) itemView.findViewById(R.id.copy_title_text);
        }
    }
}
